﻿@using Classified.Service
@using MvcPaging
@*@model IEnumerable<Classified.Domain.Entities.ClassifiedCategory>*@
@model IPagedList<Classified.Domain.Entities.ClassifiedCategory>
@{
    ViewBag.Title = "Classified Categories";
    Layout = "~/Areas/Admin/Views/Shared/_Layout.cshtml";
}
<h1>
    List of <small>Classified Categories</small></h1>
<p align="right" style="float: left" class="noprint">
    <a href="javascript:void(0);" class="btn newDetailLocation btn-info"><i class="icon-plus icon-white"></i> Create New</a>
    
</p>
<div class="clearfix pull-right">
        <label>
            Search By Category</label>
        <div class="input">
            @Html.DropDownList("CategoryList")
        </div>
    </div>
<script type="text/javascript">
    $("#CategoryList").change(function () {
        var id = $(this).val();
        url = '/Categories/' + id;
        window.location.href = url;
    })
</script>
<table class="table table-bordered table-striped">
    <thead>
        <th>
            Name
        </th>
        <th width="10%">
            Is Active
        </th>
        <th width="20%">
            Descriptions
        </th>
        <th width="">
        </th>
    </thead>
    @foreach (var item in Model)
    {
        <tr>
            <td>
                @Html.DisplayFor(modelItem => item.Name)
            </td>
            <td>
                @item.IsActive
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Description)
            </td>
            <td>
                @if (item.ClassifiedCategoryAttributes.Count() > 0)
                {
                    <a href="@Url.Action("Attributelist", "Classified", new { id = item.Id, seName = SeService.GetSeName(item.Name) })" class="btn">
                        <i class=" icon-list"></i>Attributes list</a>
                }
                <a href="@Url.Action("EditCategory", "Classified", new { id = item.Id })" idLocationDetails ="@item.Id"  class="btn editLocationDetails" idLocationDetails="@item.Id">
                    <i class=" icon-edit"></i>Edit</a> <a href="@Url.Action("DeleteCategory", "Classified", new { id = item.Id })" class="btn btn-danger" onclick="return confirm('Are you sure you wish to delete this Category and all its Classified?');">
                        <i class="icon-trash icon-white"></i>Delete</a> @*  @Html.ActionLink("Edit", "EditCategory", "Classified", new { id = item.Id }, new { idLocationDetails = item.Id, @class = "btn primary small editLocationDetails" })
                    @Html.ActionLink("Delete", "DeleteCategory", "Classified", new { id = item.Id }, new { @class = "btn small ", onclick = "return confirm('Are you sure you wish to delete this Category and all its Classified?');" })*@
            </td>
        </tr>
    }
</table>
@if (Model.TotalItemCount > 0)
{
    <div class="pagingContainer noprint">
        @Html.Pager(Model.PageSize, Model.PageNumber, Model.TotalItemCount)
    </div>
}
<script language="javascript" type="text/javascript">
    function clearErrors() {
        $('#msgErrorNewLocationDetails').html('');
        $('#msgError').html('');
    }

    function writeError(control, msg) {
        var err_msg = '<div class="alert-message error"><a class="close" href="#">×</a><p>' + msg + '</p></div>';
        $('#' + control).html(err_msg);
    }

    $(document).ready(function () {

        $('.closeModal').live('click', function () {
            $('#my-modal').modal('hide');
        });
        $('.close').live('click', function () {
            $('#my-modal').modal('hide');
        });

        $('#my-modal form').live('submit', function () {
            clearErrors();

            $.post($(this).attr('action'), $(this).serialize(), function (data, status) {
                $('#my-modal').modal('hide');
               window.location.reload(true);

            }).error(function (error, status, a, b) {
                writeError('msgError', 'Error processing request. Please check errors and try again!');
                $('.modal-body p.body').html(error.responseText);

            });
            return false;
        });

        function getRequest(url) {
            $.ajax({
                url: url,
                context: document.body,
                success: function (data) {
                    $('.modal-body p.body').html(data);
                    $(this).addClass("done");
                    $('#my-modal').modal('show');
                    $('#Article').focus();
                },
                error: function (err) {
                    writeError('msgErrorNewLocationDetails', err);
                }
            });
        }

        $('a.newDetailLocation').live('click', function () {
            clearErrors();
            var url = '@Url.Action("CreateCategory", "Classified")';
            getRequest(url);

            return false;
        });


        $('.editLocationDetails').live('click', function () {
            clearErrors();

            var id = $(this).attr("idLocationDetails");
            var url = '@Url.Content("~/Admin/Classified/EditCategory")/' + id;

            getRequest(url);

            return false;
        });




    }); 
</script>
<div id="my-modal" class="modal hide fade">
    <div class="modal-header">
        <a href="#" class="close">&times;</a>
        <h3>
            Category details</h3>
    </div>
    <div class="modal-body">
        <div id="msgError">
        </div>
        <p class="body">
        </p>
    </div>
    <div class="modal-footer">
    </div>
</div>
